<?php

Raise::load('core.RaiseStringFormatter');

/**
 * TestCoreRaiseStringFormatter class
 * Testing unit of 'phpraise/core/RaiseStringFormatter.php'
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.UnitTest.Test
 */
class TestCoreRaiseStringFormatter extends RaiseTest {
    
    public static function testClass(){
        self::assertClassExists('RaiseStringFormatter');
        self::assertClassImplements('RaiseStringFormatter', 'IRaiseFormatter');
        self::assertClassMethod('RaiseStringFormatter', 'parse');
        self::assertClassMethod('RaiseStringFormatter', 'format');
    }

    public static function testFormatting(){
        $x = 'There %s %d %s.';
        $f = new RaiseStringFormatter($x);
        self::assertStrictEqual($f->format(), $x);
        $a = array(
          'cat' => 5,
          'dog' => 1,
          'wound' => 6,
        );
        foreach($a as $k => $v){
            $t = RaiseInflector::quantify($v, 'is', 'are');
            $s = $f->parse($t, $v, RaiseInflector::quantify($v, $k));
            self::assertStrictEqual($s, sprintf($f->format(), $t, $v, RaiseInflector::quantify($v, $k)));
        }
        
    }

}
